package tests;

import java.sql.*;

public class jdbc {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        String DriverName = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/campus";
        String username = "root";
        String password = "123456";
        Class.forName(DriverName);
        Connection con = DriverManager.getConnection(url,username,password);
        String sql = "select * from tb_admin";
        Statement statement = con.createStatement();
        ResultSet rs = statement.executeQuery(sql);
        while (rs.next()){
            int id = rs.getInt("id");
            String name = rs.getString("name");
            System.out.println("id:"+id+"name:"+name);
        }
        rs.close();
        statement.close();
        con.close();
    }
}
